import axios from 'axios'
import _ from 'lodash'

const request = (config = {}) => {
  const { url } = config
  const omitConfig = _.omit(config, ['url'])

  const _baseURL = '/api/v1'

  const _config = {
    url: _baseURL + url,
    timeout: 5000,
    method: 'get',
    headers: {
      // 'estateId': sessionStorage.getItem('estateId') || '51B6745D5F18BB273765F22DF3FC71A9'
      // 'estateId': sessionStorage.getItem('estateId') || '250240D185CA1E3CAD1CC630076B6A8F'
    },
    ...omitConfig
  }

  const promise = axios(_config)
    .then(result => {
      const body = result.data
      return Promise.resolve(body)
      // if (body.code === '00000') {
      //   return Promise.resolve(body)
      // } else {
      //   return Promise.reject(body)
      // }
    })
  return promise
}
export default request
